<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page pageEncoding="UTF-8" %>
<%@ page import="java.util.*,jp.co.technotree.apl.cmd.master.Mst0001Bean.*" %>
<%@ include file="../common/common.jsp"%>
<%@page import="jp.co.technotree.apl.dao.master.MasterBean,jp.co.technotree.apl.dao.master.MasterUploadInfoBean"%>
<jsp:useBean id="formBean" class="jp.co.technotree.apl.cmd.master.Mst0001Bean" scope="request" />
<%
ApplicationManager		context		= ApplicationManager.getInstance();
String					SystemName	= context.getAppConfig("userconfig.system");
String					DateWidth	= "width=13%";								//日時
String					KindWidth	= "width=8%";								//種別
String					FNameWidth	= "width=35%";								//ファイル名
String					NoteWidth	= "width=25%";								//備考
String					UserWidth	= "width=15%";								//登録者
String					DLWidth		= "width=4%";								//DL
%>

<html>
	<head>
		<title><%= SystemName %> マスター登録</title>
		<link rel="SHORTCUT ICON" href="../common/img/default/sys_icon.ico">

		<link rel='stylesheet' type='text/css' href='../../common/css/common/base.css' >
		<link rel='stylesheet' type='text/css' href='../../common/css/common/common.css'>
		<link rel='stylesheet' type='text/css' href='../../common/css/master/master.css'>

		<script language="javascript" src="../../common/js/base.js"></script>
		<script language="javascript" src="../../common/js/menu/topmenu.js"></script>

		<!-- システムログ -->
		<script src="../../common/js/systemlog.js"></script>

			<style type='text/css'>
				.LinkItem {
					cursor: pointer;
				}
			</style>

		<script language="javascript">
			function onInit(){
				topBackChange(2);
				httpRequest();
			}
			function screen_back() {
				location.href="../topmenu/top3000.fw";
			}

			function changeSelectMaster(){
				var frm = document.main;

				mast = document.getElementById('selectMaster');
				res1 = document.getElementById('LastMsg1');
				resUS = document.getElementById('LastMsgUS');
				resCH = document.getElementById('LastMsgCH');
				resLI = document.getElementById('LastMsgLI');
				resSA = document.getElementById('LastMsgSA');

				var sel = mast.options[mast.selectedIndex].value;

				res1.style.display = 'none';
				resUS.style.display = 'none';
				resCH.style.display = 'none';
				resLI.style.display = 'none';
				resSA.style.display = 'none';
				if (sel == "US" ){
					resUS.style.display = 'inline';
				}else if ( sel == "CH" ){
					resCH.style.display = 'inline';
				}else if ( sel == "LI" ){
					resLI.style.display = 'inline';
				}else if ( sel == "SA" ){
					resSA.style.display = 'inline';
				}else{
					res1.style.display = 'inline';
				}


			}

			function fileDownload(val1){
		//		window.open('../download/downloadMaster.fw?UploadID='+val1,null,"width=10, height=10");
		//		var features="location=no, menubar=no, status=no, scrollbars=no, resizable=yes, toolbar=no, width=510, height=400";
		//		var features="location=no, menubar=no, status=no, scrollbars=no, resizable=yes, toolbar=no, width=10, height=10";
		//		window.open("../download/downloadMaster.fw?UploadID="+val1, "_blank", features);
				var features="location=no, menubar=no, status=no, scrollbars=no, resizable=yes, toolbar=no, width=510, height=400";
				window.open("../download/downloadMaster?UploadID=" + val1  , "_blank", features);
			}

			function doUpload() {
				var frm = document.main;
				frm.cmd.value="cmd01";
				var upMasterName="";
				var upMasterType="";
				var submitType   = document.getElementById('submitType');
				var uplodFile   = document.getElementById('uplodFile');
				submitType.value =frm.selectMaster.value;
				uplodFile = frm.uploadFile.value;

				var retIndex =  uplodFile.lastIndexOf("\\",1024);
				if( retIndex > 0 ){
					uplodFile = uplodFile.substr(retIndex+1,1024);
				}

				upMasterType = submitType.value;
				if ( submitType.value == "" ){
					if ( uplodFile.substr(0,4) == "ユーザー"){
						upMasterType="US";
					}
					if ( uplodFile.substr(0,4) == "機器機番"){
						upMasterType="EQ";
					}
					if ( uplodFile.substr(0,2) == "期間"){
						upMasterType="TM";
					}
					if ( uplodFile.substr(0,4) == "作業区分"){
						upMasterType="WK";
					}
				}

				if ( upMasterType == "US" ){
					upMasterName="ユーザーマスター";
				}else if ( upMasterType == "EQ" ){
					upMasterName="機器機番マスター";
				}else if ( upMasterType == "TM" ){
					upMasterName="期間マスター";
				}else if ( upMasterType == "WK" ){
					upMasterName="作業区分マスター";
				}
				//if( upMasterType != ""){
					if( uplodFile == "" ){
						alert("エクセルファイルを指定してください。");
						return;
					}
					if ( uplodFile.length > 3 ) {
						if( uplodFile.substr(uplodFile.length -3 , 3).toUpperCase() != "XLS") {
							alert("拡張子が違います。エクセルファイルを指定してください。");
							return;
						}
					}
					if (!confirm(upMasterName + "のアップロードを行います。よろしいですか？") ) {
						return ;
					}
				//}

				frm.upTest.value="0";
				if( frm.chkUpTest.checked == true ) frm.upTest.value="1";

				res1 = document.getElementById('resultMsg1');
				res2 = document.getElementById('resultMsg2');
				res3 = document.getElementById('resultMsg3');
				res1.style.display = 'none';
				res2.style.display = 'inline';
				res3.style.display = 'none';

				submitType.value=upMasterType;

				frm.submit();
			}
			function updateSerch(){
				var frm = document.main;
				var submitType   = document.getElementById('submitType');

				frm.upTest.value="0";
				if( frm.chkUpTest.checked == true ) frm.upTest.value="1";

				submitType.value="SERTCH";
				frm.submit();
			}

			</script>

	</head>

	<body onLoad="onInit()" style="margin: 0px 4px 0px 0px;">
		<form class="frmMain" name="main" action="./mst0001.fw" method="post" enctype="multipart/form-data">
			<table class="tblMain" width="100%" cellspacing="0" cellpadding="0" border="0">
				<tr>
					<td valign="top">
						<table class='main-width-tb'  cellspacing='0' cellpadding='0' border='0'><tr><td></td></tr></table>
						<table class='main-height-tb' cellspacing='0' cellpadding='0' border='0'><tr><td></td></tr></table>

						<!-- Header Menu START -->
						<jsp:include page="jsp/common/headermenu.jsp"></jsp:include>
						<!-- Header Menu END -->

						<!-- ***** [FORM] MAIN-FORM ***** -->
						<div id="lc-out" style="z-index: 0;">
							<div id="lc-in" style="z-index: 0">
								<div style="text-align: center; margin: 20px ; border: solid 1px black; background-color: white ; width: 98%;">
									<table border="0" cellpadding="0" cellspacing="0"  style="width: 98%;">
										<colgroup width=33% ></colgroup>
										<colgroup width=33% ></colgroup>
										<colgroup width=34% ></colgroup>
										<tr style="height: 5px"><td colspan=3>&nbsp;</td></tr>
										<tr>
											<td>マスター種別</td>
											<td>最終登録日時</td>
											<td>状態</td>
										</tr>
										<tr>
											<td>
												<select class="select_btn" name="selectMaster" onchange="changeSelectMaster()">
													<option value="">自動判断</option>
													<option value="US">ユーザー</option>
													<option value="EQ">機器機番</option>
													<option value="TM">期間</option>
													<option value="WK">作業区分</option>
												</select>
											</td>
											<td>
												<div id="LastMsg1">&nbsp;</div>
												<div id="LastMsgUS" style="display:none"><%=formBean.getLastUStime() %></div>
												<div id="LastMsgCh" style="display:none"><%=formBean.getLastCHtime() %></div>
												<div id="LastMsgLI" style="display:none"><%=formBean.getLastLItime() %></div>
												<div id="LastMsgSA" style="display:none"><%=formBean.getLastSAtime() %></div>
											</td>
											<td>
												<% if ("".equals(formBean.getResult()) || formBean.getResult() == null ) { %>
													<div id="resultMsg1">&nbsp;</div>
												<% }else{ %>
													<% 	String sRet = formBean.getResult();
														String[] vRet = sRet.split(",");
														%>
														<div class="LinkItem" onClick="javaScript:logSubOpen('../systemlog1000/log1000?parentId=<%=vRet[1]%>');">
														<%
														if ( vRet[0].equals("-1") == true ) { %>
														<div id="resultMsg1" style='color: #ff0000;'>登録に失敗しました。</div>
													<% }else  if (vRet[0].equals("-2") == true ) { %>
														<div id="resultMsg1" style='color: #ff0000;'>《登録テスト》異常な情報が存在します。</div>
													<% }else  if ( vRet[0].equals("3") == true  ) { %>
														<div id="resultMsg1" style='color: #EF9500;'>《登録テスト》登録情報は警告が存在します。</div>
													<% }else  if ( vRet[0].equals("1") == true  ) { %>
														<div id="resultMsg1" style='color: #EF9500;'>登録は終了しましたが警告が存在します。</div>
													<% }else  if ( vRet[0].equals("2") == true  ) { %>
														<div id="resultMsg1" style='color: #0000ff;'>《登録テスト》登録情報は正常です。</div>
													<% }else  { %>
														<div id="resultMsg1" style='color: #0000ff;'>正常に登録を終了しました。</div>
													<% } %>
														</div>
													<%}%>
												<div id="resultMsg2" style="display:none">アップロードを行っています。</div>
												<div id="resultMsg3" style="display:none"></div>
											</td>
										</tr>
										<tr><td colspan=3>&nbsp;</td></tr>
										<tr>
											<td colspan=3>マスターファイル</td>
										</tr>
										<tr>
											<td colspan=3>
												<input type="file" style="width: 600px" name="uploadFile" value=""  >
											</td>
										</tr>
										<tr><td colspan=3>&nbsp;</td></tr>
										<tr>
											<td colspan=3 >備考</td>
										</tr>
										<tr>
											<td colspan=3>
												<input type="text" style="width: 600px"name="Note" value=""  >
											</td>
										</tr>
										<tr><td colspan=3>&nbsp;</tr>
										<tr>
											<td><input type="checkbox"  name="chkUpTest" id="chkUpTest" value="1" <% if ( formBean.getUpTest().equals("1") == true ){  %>checked <%} %> ><label for="chkUpTest" >登録テスト </label></td>
											<td style="text-align: center;">
											 	<input type="button"  class="menu-btn-up  mainBtn" style="width:150px" name="登録" value="登録" onClick="doUpload();" >
											</td>
											<td>&nbsp;</td>
										</tr>
										<tr><td colspan=3>&nbsp;</td></tr>
									</table>
								</div>
								<br>

								<div  style="margin: 20px ; border: solid 1px black; background-color: white ; width: 98%;">
									<table  border="0" style="width: 98%;">
										<tr>
											<td>
												<table  border="0" width=98%>
												<tr>
													<td>登録履歴&nbsp&nbsp&nbsp&nbsp&nbsp</td>
													<td>
														種別：
														<select class="select_btn" name="serchFileType">
															<option value="" <%if("".equals(formBean.getSerchFileType())){ %> selected <%} %>>全て</option>
															<option value="US" <%if("US".equals(formBean.getSerchFileType())){ %> selected <%} %>>ユーザー</option>
															<option value="EQ" <%if("EQ".equals(formBean.getSerchFileType())){ %> selected <%} %>>機器機番</option>
															<option value="TM" <%if("TM".equals(formBean.getSerchFileType())){ %> selected <%} %>>期間</option>
															<option value="WK" <%if("WK".equals(formBean.getSerchFileType())){ %> selected <%} %>>作業区分</option>
														</select>
													</td>
													<td>ファイル名：<input type="text" name="serchFileName" style="width:150px" value="<%=formBean.getSerchFileName() %>">
													</td>
													<td>備考：<input type="text" name="serchBiko" style="width:150px" value="<%=formBean.getSerchBiko() %>">
													<td>
														<input type="button" value="検索"   class="button"  style="width:90px"onclick="updateSerch()">
													</td>
													</tr>
												</table>
											</td>
										</tr>
										<tr>
											<td>
												<div style="border: solid 1px;">
													<div  style="height:21px; overflow-y:scroll;background: #FFFFFF;">
														<table  border="1" width=100% class="data-grid">
															<colgroup <%= DateWidth %>></colgroup>
															<colgroup <%= KindWidth %>></colgroup>
															<colgroup <%= FNameWidth %>></colgroup>
															<colgroup <%= NoteWidth %>></colgroup>
															<colgroup <%= UserWidth %>></colgroup>
															<colgroup <%= DLWidth %>></colgroup>
															<thead>
																<tr>
																	<th>日時</th>
																	<th>種別</th>
																	<th>ファイル名</th>
																	<th>備考</th>
																	<th>登録者</th>
																	<th>DL</th>
																</tr>
															</thead>
														</table>
													</div>

													<div  style="height: 200px; overflow-y: scroll; background: #FFFFFF;">
														<table  border="1"  width=100% class="data-grid">
															<colgroup <%= DateWidth %>></colgroup>
															<colgroup <%= KindWidth %>></colgroup>
															<colgroup <%= FNameWidth %>></colgroup>
															<colgroup <%= NoteWidth %>></colgroup>
															<colgroup <%= UserWidth %>></colgroup>
															<colgroup <%= DLWidth %>></colgroup>
															<%
																//----------------------------------------
																//登録履歴一覧の取得
																//----------------------------------------
																MasterUploadInfoBean[] revisionList = formBean.getRevisionList();
																if ( revisionList != null ){
																	for ( int i=0; i<revisionList.length; i++ ){
																		MasterUploadInfoBean rbean = revisionList[i];
															%>
															<tr>
																<td nowrap class="td-left" title="<%=rbean.uploadDatetime%>"    ><%=rbean.uploadDatetime %></td>
																<td class="td-left" title="<%=rbean.displyCate%>"    ><%=rbean.displyCate %></td>
																<td class="td-left" title="<%=rbean.uploadFilename%>"><%=rbean.displyFilename %></td>
																<td class="td-left" title="<%=rbean.note%>"><%=rbean.displyNote %> </td>
																<td class="td-left" title="<%=rbean.empNm%>"><%=rbean.displyEmpName %> </td>
																<% if ( rbean.downloadFilename == null ){ %>
																<td>&nbsp;</td>
																<% }else{ %>
																<td align='center'><a href="#"><span onClick="javaScript:fileDownload('<%= rbean.uploadID %>')">DL</span></a></td>
																<% } %>
															</tr>
															<%
																	}
																}
															%>
														</table>
													</div>
												</div>
											</td>
										</tr>
									</table>
								</div>
							</div><!-- lc-in End -->


							<!-- ログ Start -->
							<div class="log-box">
								<div class="log-out">
									<div class="log-title">ログ</div>
									<div class="log-in">
										<div id="divOutput"></div>
									</div>
								</div>
							</div>
							<!-- ログ End -->

						</div><!-- lc-out  -->
					</td>
				</tr>
			</table>

			<input type="hidden" name="cmd" value="cmd01">
			<input type="hidden" name="submitType" id="submitType" value="">
			<input type="hidden" name="uplodFile" id="uplodFile" value="">
			<input type="hidden" name="deleteSheet" id="deleteSheet" value="">
			<input type="hidden" name="deleteSheetName" id="deleteSheetName" value="">
			<input type="hidden" name="upTest" id="upTest" value="">
		</form>
	</body>
</html>
